##: Makefile - for GDR programs
# @author Matt Stallmann
# @date 2001/12/29
# $Id: Makefile 10 2007-06-28 20:08:57Z mfms $

#  Copyright (C) 1989, 2001, 2007  Matthias Stallmann, Prashant Hebbar.
#  Contact: matt_stallmann@ncsu.edu
#
#  This program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2 of the License, or
#  (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License along
#  with this program (file COPYING.txt); if not, write to the Free Software
#  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
#  USA.

CC = gcc
X11_DIR = /usr/X11R6
X11_INCLUDE = $(X11_DIR)/include
X11_LIB_DIR = $(X11_DIR)/lib
CFLAGS = -g -c -Wall -I$(X11_INCLUDE) # when doing strict checking
#CFLAGS = -g -c -Wall -DDEBUG -I$(X11_INCLUDE) # when debugging
LFLAGS = -L$(X11_LIB_DIR) -lX11 -lm	  # libraries for the linker
# LFLAGS = -L$(X11_LIB_DIR) -lX11 -lnsl -lsocket -lm # extra libs (when needed)

.c.o: ;
	$(CC) $(CFLAGS) $<

PROG_HEADERS = Gdr.h Display.h Geometric.h Logical.h Macros.h Misc.h Makefile TextWindowList.h
ALL_HEADERS = $(PROG_HEADERS) All.h Defs.h Globals.h Prototypes.h Settings.h

GDR_OBJECTS = Main.o Gdr.o Utilities.o List.o Panel.o InOut.o Text.o TextWindowList.o

EXECUTABLES = dfa minimize dfs_scc dijkstra bfs kruskal crossings print_logical

all: $(EXECUTABLES)

Utilities.o: Utilities.c $(ALL_HEADERS)

Panel.o: Panel.c $(ALL_HEADERS)

InOut.o: InOut.c $(ALL_HEADERS)

List.o: List.c $(ALL_HEADERS)

Text.o: Text.c $(ALL_HEADERS)

TextWindowList.o: TextWindowList.c $(ALL_HEADERS)

Gdr.o: Gdr.c $(ALL_HEADERS)
# special instructions for compiling Gdr.c (because of usleep) --
	$(CC) $(CFLAGS) -DUSLEEP Gdr.c
#	$(CC) $(CFLAGS) -DPROCESSOR_SPEED=5 list

# all animations

# finite automaton animations
dfa: Main.c dfa.o $(GDR_OBJECTS)
	$(CC) $(CFLAGS) -DICON='"== DFA Simulator =="' -DDIRECTED Main.c
	$(CC) -o dfa -g dfa.o $(GDR_OBJECTS) $(LFLAGS)

chk_dfa: Main.c alphabet.o chk_dfa.o $(GDR_OBJECTS)
	$(CC) $(CFLAGS) -DICON='"CHECK DFA"' -DDIRECTED Main.c
	$(CC) -o chk_dfa -g alphabet.o chk_dfa.o $(GDR_OBJECTS) $(LFLAGS)

minimize: Main.c alphabet.o minimize.o $(GDR_OBJECTS)
	$(CC) $(CFLAGS) -DICON='"|__ DFA Minimization __|"'\
        -DDIRECTED Main.c
	$(CC) -o minimize -g alphabet.o minimize.o $(GDR_OBJECTS) $(LFLAGS)

alphabet.o: alphabet.c alphabet.h general.h
#	$(CC) -c -DDEBUG -g -o alphabet.o alphabet.c

dfa.o: dfa.c $(PROG_HEADERS)

chk_dfa.o: chk_dfa.c alphabet.h general.h $(PROG_HEADERS)

minimize.o: minimize.c alphabet.h general.h $(PROG_HEADERS)

# algorithm animations (for CSC 505)

print_logical: Main.c print_logical.o $(GDR_OBJECTS)
	$(CC) $(CFLAGS) -DICON='"Print a logical version of this graph"' Main.c
	$(CC) -o print_logical -g print_logical.o $(GDR_OBJECTS) $(LFLAGS)

dfs_d: Main.c dfs_d.o $(GDR_OBJECTS)
	$(CC) $(CFLAGS) -DICON='"^^ DFS (directed graphs) vv"' -DDIRECTED Main.c
	$(CC) -o dfs_d -g dfs_d.o $(GDR_OBJECTS) $(LFLAGS)

bfs: Main.c bfs.o $(GDR_OBJECTS)
	$(CC) $(CFLAGS) -DICON='"^^ BFS (directed graphs) vv"' -DDIRECTED  Main.c
	$(CC) -o bfs -g bfs.o $(GDR_OBJECTS) $(LFLAGS)

kruskal: Main.c kruskal.o $(GDR_OBJECTS)
	$(CC) $(CFLAGS) -DICON='"^^ KRUSKAL (undirected graphs) vv"'  Main.c
	$(CC) -o kruskal -g kruskal.o $(GDR_OBJECTS) $(LFLAGS)

dfs_scc: Main.c dfs_scc.o $(GDR_OBJECTS)
	$(CC) $(CFLAGS) -DICON='"<-> DFS (directed graphs/SCC) <->"' -DDIRECTED Main.c
	$(CC) -o dfs_scc -g dfs_scc.o $(GDR_OBJECTS) $(LFLAGS)

prim: Main.c prim.o $(GDR_OBJECTS)
	$(CC) $(CFLAGS) -DICON='"_|_ Prim/Dijkstra/Jarnik MST Algorithm -|-"' Main.c
	$(CC) -o prim -g prim.o $(GDR_OBJECTS) $(LFLAGS)

dijkstra: Main.c dijkstra.o $(GDR_OBJECTS)
	$(CC) $(CFLAGS) -DICON='"-> The Dijkstra SSSP/MST Algorithm -|"' Main.c
	$(CC) -o dijkstra -g dijkstra.o $(GDR_OBJECTS) $(LFLAGS)

crossings: Main.c crossings.o $(GDR_OBJECTS)
	$(CC) $(CFLAGS) -DICON='"X* Crossing Minimization *X"' Main.c
	$(CC) -o crossings -g crossings.o $(GDR_OBJECTS) $(LFLAGS)

dfs_d.o: dfs_d.c $(PROG_HEADERS)

bfs.o: bfs.c $(PROG_HEADERS)

kruskal.o: kruskal.c $(PROG_HEADERS)

dfs_scc.o: dfs_scc.c $(PROG_HEADERS)

prim.o: prim.c $(PROG_HEADERS)

dijkstra.o: dijkstra.c $(PROG_HEADERS)

crossings.o: crossings.c $(PROG_HEADERS)

# clean up the directory (remove all machine-generated files)
clean: 
	rm -f *.o *.bak *~ $(EXECUTABLES)

# keep the executables
semi_clean: 
	rm -f *.o *.bak *~
